package com.service.utills;

import android.content.Context;
import android.util.Log;

import org.json.JSONObject;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;

/**
 * Created by rora0613 on 30.09.13.
 */
public class DataTransfer {
    public static final String IP = "10.0.2.2";
    public static final int PORT = 4486;
    private Socket client;
    private PrintWriter printwriter;

    public void sendDateToServer(final JSONObject data) {

        new Thread(new Runnable() {
            public void run() {
                try {

                    client = new Socket(IP, PORT);  //connect to server
                    printwriter = new PrintWriter(client.getOutputStream(), true);
                    printwriter.write(data.toString());  //write the JSONObject to output stream
                    printwriter.flush();
                    printwriter.close();

                } catch (UnknownHostException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }).start();

    }


}
